void makeSerial(int tempIndex){
  myPort[sP] = new Serial(this, Serial.list()[1], 57600,'N',8, 1);
  myPort[sP].buffer(2);
  serialList[sP]=tempIndex-1;
  sP++;
}

void checkSerial(){
  for(int i=0;i<sP;i++){
    if(myPort[i].available()>0){
      String tempS=myPort[i].readString();
      if(tempS.length()>1){
        //mC[parentIndex].mods[serialList[i]].message=": "+int(tempS.charAt(0))+" "+int(tempS.charAt(1));
        //mC[parentIndex].mods[serialList[i]].go();
      }
    }
  }
}

class serialInMod extends Mod
{




  serialInMod(Mod tempParent, float tempBx, float tempBy, int tempIndex){
    super(tempParent,tempBx,tempBy,tempIndex);
    makeSerial(tempIndex);
    img="srl";
    loadImg(img);
    name="serial";
    minWx=50;
    minWy=50;
    oPs[op]=new outPort(this,1,"out");
    updatePorts();
    isInput=true;
  }

  void go() {
    sendString(message, 0);

    //delay(10);
    doStack();
  }

}

class serialOutMod extends Mod
{
  serialOutMod(Mod tempParent, float tempBx, float tempBy, int tempIndex){
    super(tempParent,tempBx,tempBy,tempIndex);
    img="srl";
    loadImg(img);
    name="serial";
    minWx=50;
    minWy=50;
    iPs[ip]=new inPort(this,1,"in");
    updatePorts();    
  }

  void go() {
    String tokens[]=splitTokens(iPs[0].stringV, " /");
    //println(tokens);
    if(tokens[1].equals("led")){
      println("int: "+int(tokens[4])+" char: "+char(int(tokens[4])));
      println(str(char(int(tokens[4])))+str(char(int(tokens[2])+int(tokens[3])<<4)));
      myPort[0].write(str(char(int(tokens[4])+32))+str(char(int(tokens[2])+int(tokens[3])*16)));
    }
    /*myMessage = new OscMessage(tokens[0]);
    for(int i=1;i<tokens.length;i++){
      myMessage.add(int(tokens[i])); 
    }
    oscOut.send(myMessage, myRemoteLocation);
    */

  }
}
